// index.js
//引入发送请求的方法
import { request } from "../../request/index.js"
Page({

    /**
     * 页面的初始数据
     */
    data: {
        //轮播图数组
        swiperList: [],
        //分类导航数据
        CatesList: [],
        //楼层数据
        floorList: []
    },

    /**
     * 生命周期函数--监听页面加载 
     * 页面开始加载
     */
    onLoad: function (options) {
        //1发送请求获取轮播图数据
        // wx.request({
        //     url: 'https://api-hmugo-web.itheima.net/api/public/v1/home/swiperdata',
        //     method:'GET',
        //     //成功
        //     success: (result) => {
        //         console.log(result.data)
        //         this.setData({
        //             swiperList:result.data.message
        //         })
        //     }
        // });
        this.getSwiperList()
        this.getCateList()
        this.getFloorList()
    },
    //调用轮播图数据
    async getSwiperList() {
        // request({ url: '/home/swiperdata' }).then(result => {
        //     this.setData({
        //         swiperList: result.data.message
        //     })
        // })
        let res = await request({ url: '/home/swiperdata' })
        let swiperList=res.data.message
        swiperList.forEach(v => {
            v.navigator_url=v.navigator_url.replace("main","goods_detail")
        });
        console.log(swiperList);
        this.setData({
            swiperList
        })

    },
    //获取分类导航数据
    async getCateList() {
        let res = await request({ url: '/home/catitems' })
        this.setData({
            CatesList: res.data.message
        })
    },
    //获取楼层数据
    async getFloorList() {
        let res = await request({ url: '/home/floordata' })
        let floorList= res.data.message
        floorList.forEach(v => {
            console.log(v.product_list);
            v.product_list.forEach(item => {
                 item.navigator_url=item.navigator_url.replace(/\?/i,"/goods_list?")
            });
        });
        this.setData({
            floorList
        })
    },
})